package leetcode.easy;

/**
 * ClassName: $169_MajorityElement
 * Description:
 * date: 2022-02-18 23:48
 *
 * @author liyifan
 */
public class $169_MajorityElement {
    public int majorityElement(int[] nums) {
        int cand = nums[0];
        int count = 1;
        for (int i = 1;i < nums.length;i++) {
            if (cand == nums[i]) {
                count++;
            } else {
                count--;
            }

            if (count == 0) {
                cand = nums[i];
                count = 1;
            }
        }
        return cand;
    }
}
